package gui.cen.home;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class HTMLRenderer extends JPanel{

    private JEditorPane htmlRend;
    public HTMLRenderer(){
        super(new GridLayout());
        htmlRend = new JEditorPane();
        htmlRend.setEditable(false);
        htmlRend.setContentType("text/html");
        htmlRend.setBackground(new Color(102, 102, 102));
        htmlRend.setForeground(new Color(178, 178, 178));
        htmlRend.addHyperlinkListener(
            new HyperlinkListener(){
                public void hyperlinkUpdate(HyperlinkEvent event) {
                    if(event.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
                        try{
                            //htmlRend.setPage(event.getURL());
                            java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
                            java.net.URI uri = new java.net.URI(event.getURL().toString());
                            desktop.browse( uri );

                        }catch(Exception e){htmlRend.setText("Error: "+e);}
                    }
                }
            }
        );

        htmlRend.setEditable(false);
        JScrollPane scroller = new JScrollPane(htmlRend);
        scroller.setBorder(null);
        scroller.setWheelScrollingEnabled(true);
        add(scroller);
    }

    public void renderFrontEnd(){
        String html = "<html><body color=\"#999999\"   align=\"center\">";
        String imgsrc = this.getClass().getResource("/images/fig_1.png").toString();
        html = html + "<img src=\""+imgsrc+"\">";
        html = html +
            "<p><b>Segminator II has been developed and implemented by <a STYLE=\"color: #999999;\" href=\"http://www.phylogenetictrees.com/publications.php\">John Archer</a>, for a project supervised by <a STYLE=\"color: #999999;\" href=\"http://www.bioinf.manchester.ac.uk/robertson/\">David Robertson</a> and <a STYLE=\"color: #999999;\" href=\"http://tree.bio.ed.ac.uk/people/arambaut/\">Andrew Rambaut</a>."+
            " It is a tool for the analysis of <b>viral</b> short read data. " +
            "Please visit the <a STYLE=\"color: #999999;\" href=\"http://www.bioinf.manchester.ac.uk/segminator/\">website</a> (or view <a STYLE=\"color: #999999;\" href=\"http://www.ncbi.nlm.nih.gov/pubmed/22443413\">Archer <i>et al.</i>, 2012</a>) for further details.</b></p>";
        html = html + "</body></html>";
        try{htmlRend.setText(html);}
        catch(Exception e){}
    }
}